import { Component } from '@angular/core';
import {App, IonicPage, MenuController, ModalController, NavController} from 'ionic-angular';
import {Item} from "../../models/item";
import {Items} from "../../providers/providers";

import { AlertController } from 'ionic-angular';
import {LoginPage} from "../login/login";
import {FirstRunPage} from "../pages";
import {NoticePage} from "../notice/notice";
import { localbase } from '../../models/localbase';

/**
 * Generated class for the UserPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-user',
  templateUrl: 'user.html',
})
export class UserPage {

  currentItems: Item[];
  
  AutoSc;


  constructor(public navCtrl: NavController, public items: Items, public modalCtrl: ModalController, menu: MenuController, private app: App,public alertCtrl: AlertController
    ,public localbasefun: localbase) {

  }
  ngOnInit(){
  this.AutoSc=this.localbasefun.getAutoSc();
  if(this.AutoSc==null){
    this.AutoSc="noAuto";
  }
  }
  goPassword() {
    this.app.getRootNav().push('PasswordPage');
  }
  changeAutoSc(b){
    const localbasefun = this.localbasefun;
    if(b==0){
      localbasefun.setAutoSc("noAuto");
    }else{localbasefun.setAutoSc("Auto");}
  }
  goNewpage(){

    let confirm = this.alertCtrl.create({
      title: '您已经是最新版本',
      buttons: [
        {
          text: '取消',
          handler: () => {
            //console.log('Disagree clicked');
          }
        },
        {

          text: '确定',
          handler: () => {
            //console.log('Agree clicked');
            // this.app.getRootNav().push('LoginPage');

          }
        }
      ]

    });
    confirm.present();
  }

  clean(){
    let confirm = this.alertCtrl.create({
      title: '清楚缓存系统后，您与本机的所有帐号信息将被清空！',
      buttons: [
        {
          text: '取消',
          handler: () => {
            //console.log('Disagree clicked');
          }
        },
        {
          text: '确认',
          handler: () => {
            //console.log('Agree clicked');

          }
        }
      ]
    });
    confirm.present();
  }

  out(){
    let confirm = this.alertCtrl.create({
      title: '确认退出当前账号？',
      buttons: [
        {
          text: '取消',
          handler: () => {
            //console.log('Disagree clicked');
          }
        },
        {
          text: '确认',
          handler: () => {
            //console.log('Agree clicked');
            sessionStorage.removeItem("email");
            sessionStorage.removeItem("userid");
            sessionStorage.removeItem("username");
            sessionStorage.removeItem("pwd");
            this.app.getRootNav().setRoot(FirstRunPage);
          }
        }
      ]
    });
    confirm.present();
  }

  _name(){
    return sessionStorage.getItem("username");
  }

  notice(){
    this.navCtrl.push("NoticePage");
  }
}
